package com.study.quickstart;

import javax.servlet.http.HttpServletRequest;

/**
 * 用户登录
 *
 * @author yyb8152
 * @since 20220327
 **/
public class AccountLoginController {

    //注入dao(构造函数)
    private final AccountDao accountDao;

    public AccountLoginController(AccountDao accountDao) {
        this.accountDao = accountDao;
    }

    public String login(HttpServletRequest request){
        String userName = request.getParameter("username");
        String passWord = request.getParameter("password");
        try {
            Accout account = accountDao.findAccount(userName, passWord);
            if(account == null){
                return "/login";
            }else{
                return "/index";
            }
        }catch (Exception e){
            //db不可用
            return "/505";
        }

    }
}
